import VueRouter from "vue-router";
import Vue from 'vue'
Vue.use(VueRouter);

const Index = () => import('../view/index/index');
const Login = () => import('../view/login/Login');
const ProductMainItem = () => import('../view/index/productMainItem/ProductMainItem');
const ProductOrder = () => import('../view/index/order/productOrder');
const Shopcart = () => import('../view/index/shopcart/Shopcart');
const ProductDetail = () => import('../view/index/productDetail/ProductDetail');
const Buy = () => import('../view/index/buy/Buy');
const Comment = () => import('../components/comment/Comment');

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes=[
  {
    path: '/',
    redirect: '/index'
  },
  {
    path: '/index',
    component: Index,
    children:[{
      path: '/',
      component: ProductMainItem,
    },
      {
        path: 'order',
        component: ProductOrder
      },
      {
        path: 'shopcart',
        component: Shopcart
      },
      {
        path: 'productDetail',
        component: ProductDetail
      },
      {
        path: 'buy',
        component: Buy
      },
      {
        path: 'comment',
        component: Comment
      },
    ],
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/shopcart',
    component: Shopcart
  },
];
const router = new VueRouter({
  mode:'history',
  routes,
});

export default router
